package com.tulele.vtool.task.process.remindActivePush;

import com.tulele.vtool.bus.model.UserInfo;
import com.tulele.vtool.bus.service.IUserService;
import com.tulele.vtool.task.async.FirstTimeRemindUserActivePushAsyncTask;
import com.tulele.vtool.util.SpringContextUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@Slf4j
public class FirstTimeRemindUserActivePushScheTask extends QuartzJobBean {

    @Autowired
    private FirstTimeRemindUserActivePushAsyncTask firstTimeRemindUserActivePushAsyncTask;

    @Autowired
    private IUserService userService;

    @Value("${spring.application.name}")
    private String springProfilesActive;

    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        String profiles_str = springProfilesActive;//获取环境
        String[] profile_arr = profiles_str.split(",");
        List<Integer> headIds = new ArrayList<>();
        for (String profile : profile_arr) {
            List<UserInfo> userList = userService.getUserListByGzhCode(profile);
            for (UserInfo userInfo : userList) {
                firstTimeRemindUserActivePushAsyncTask.execute("wxPushUser" + userInfo.getUserId(),profile,userInfo);
            }
        }
    }
}
